package com.sunchen.asc.service.item.repository;

import com.sunchen.asc.service.item.domain.Basis;
import com.sunchen.asc.service.item.vo.BasisVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BasisRepository extends JpaRepository<Basis,Long> {

    @Modifying
    @Query("delete from Basis t where t.itemId = ?1")
    void deleteAllByItemId(Long itemId);

    @Query("select new com.sunchen.asc.service.item.vo.BasisVo(t.id,t.itemId,t.code,t.name,t.unitName,t.content,t.fileId,t.fileName,t.type,t.sortOrder) from Basis t where t.itemId = ?1 order by t.sortOrder asc")
    List<BasisVo> getVosByItemId(Long itemId);
}
